package com.hzhr.iot.user.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.user.controller.base.BaseController;
import com.hzhr.iot.user.model.role.RoleGetModel;
import com.hzhr.iot.user.service.RoleService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "Role", description = "角色")
@RestController
@RequestMapping(value = "")
public class RoleController extends BaseController {
    @Autowired
    RoleService roleService;

    //region /roles GET
    //region swagger响应码 : get
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : get
    @ApiOperation(value="查询角色", notes="查询角色  \n简介 : 查询角色  \n步骤 :  \n1. 查询角色 : (√)  \n 根据条件参数查询角色(ROLE)；  \n2. 返回信息 : (√)  \n 根据条件参数和查询到的结果组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "角色编号",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_name", value = "角色名称",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "equal_companyId", value = "筛选条件 : where role.companyId = #{equal_companyId}",required = false, dataType = "int", paramType = "query"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_is_paging", value = "是否分页", defaultValue = "true",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where role.id = #{_equal_id}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_name", value = "筛选条件 : where role.id = #{_equal_name}",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_equal_companyId", value = "筛选条件 : where role.companyId = #{_equal_companyId}",required = false, dataType = "int", paramType = "query"),
    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/roles", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<RoleGetModel> get(@RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        RoleGetModel responseBody = roleService.get(initHeader(), query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
    //region /v1/roles GET
    //region swagger响应码 : get1
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询角色  \n----异常说明 : 登录用户的所属公司不存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : get1
    @ApiOperation(value="查询角色", notes="查询角色  \n简介 : 查询登录用户公司下的所有角色  \n步骤 :  \n1. 查询角色 : (√)  \n根据条件参数查询角色(ROLE)对象集合roleList_1及总数，  \n额外筛选条件如下：  \n          (1) 根据登录用户.companyId查询用户的所属公司company_1，查询方式如下：  \n                    以GLOBAL方式调用companyService.get()服务获取CompanyModel模型对象作为company_1，  \n                    CompanyModel模型对象与登录用户.companyId的对应关系如下：  \n                              CompanyModel模型对象.id = 登录用户.companyId；  \n          如果company_1不存在，抛出异常201；  \n          如果company_1.type = userOptions.getCode('COMPANY_TYPE','GAS_COMPANY'),那么，  \n          roleList_1[i].id = 1 or roleList_1[i].id = 2 or roleList_1[i].companyId = 登录用户.companyId；  \n          如果company_1.type = userOptions.getCode('COMPANY_TYPE','IOT_DEVICE_COMPANY'),那么，  \n          roleList_1[i].id = 3 or roleList_1[i].id = 4 or roleList_1[i].companyId = 登录用户.companyId；  \n2. 返回信息 : (√)  \n根据条件参数和查询到的roleList_1及总数生成结果对象并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get1
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "is_paging", value = "是否分页", defaultValue = "false",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_is_paging", value = "是否分页", defaultValue = "false",required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
    })
    //endregion
    //region 请求 : get1
    @RequestMapping(value = "/v1/roles", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<RoleGetModel> get1(@RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        RoleGetModel responseBody = roleService.get1(initHeader(), query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}
















































































































































































































































































































































































